<?php
class HistoricoMantoPrevController extends AppController {

	var $name = 'HistoricoMantoPrev';
	var $uses = array('MntPrevVehiculo', 'Vehiculo', 'MantPrev', 'Poliza');
	var $helpers = array('Html', 'Form' );
	
	function beforeFilter() {		
		$this->checkSession();
		$this->MenuCreator->setModulo($this->name);
		$this->set('menu', $this->getMenuElements());
	}

	function index() {		
		$this->set('mantenimientos', $this->paginate());
	}

	function ver($id = null) {			
		$this->MntPrevVehiculo->recursive = 1;
			
		if(!$id) {
			$this->Session->setFlash('Vehiculo Invalido');
			$this->redirect(array('action'=>'index'), null, true);
		}	

		$this->set('MntPrevVehiculo', $this->MntPrevVehiculo->read(null, $id));
	}

	function agregar() {
		if(!empty($this->data)) {
			$this->cleanUpFields();
			$this->MntPrevVehiculo->create();

			if($this->MntPrevVehiculo->save($this->data)) {
				$this->Session->setFlash('El Manto Preventivo del Vehiculo ha sido agregado');
				$this->redirect(array('action'=>'index'), null, true);
			} else {
				$this->Session->setFlash('El Manto Preventivo del Vehiculo no pudo ser agregado. Por favor intenta de nuevo.');
			}
		}
		else{
			$this->set('mantenimientos', $this->MantPrev->generateList());
			$this->set('vehiculos', $this->Vehiculo->generateList());
			$this->set(compact('proveedores','vehiculos'));
		}
	}
}
?>
